class Sample():
    def __enter__(self):
        print("enter")
        return self

    def __exit__(self, exc_type, exc_val, exc_tb):
        print("exit")

    def do_some_thing(self):
        print("do.......")


if __name__ == "__main__":
    s = Sample()
    s.do_some_thing()
    '''
    上下文管理器
    '''
    with Sample() as sample:
        sample.do_some_thing()
